<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Reservations</title>
    </h:head>
    <h:body>
        <h:form>
            <p:messages id="messages" showDetail="true" showSummary="true"/>

            <p:spacer height="10px" />

            <p:toolbar>
                <p:commandButton value="New reservation" image="ui-icon-document"
                                 action="#{roomsBackingBean.newReservation}"
                                 update="table"/>
            </p:toolbar>

            <p:spacer height="10px" />

            <p:dataTable id="table" var="row" value="#{roomsBackingBean.selectedRoom.reservations}"
                         selection="#{roomsBackingBean.selectedReservation}"
                         selectionMode="single"
                         update="details">
                <f:facet name="header">Reservations for #{roomsBackingBean.selectedRoom.name}</f:facet>
                <p:column resizable="1">
                    <f:facet name="header">From</f:facet>
                    #{row.resFrom}
                </p:column>
                <p:column resizable="true">
                    <f:facet name="header">Until</f:facet>
                    #{row.resTo}
                </p:column>
                <p:column resizable="true">
                    <f:facet name="header"># People</f:facet>
                    #{row.numberOfPeople}
                </p:column>
                <p:column resizable="true">
                    <f:facet name="header">Contact person</f:facet>
                    #{row.contactPerson}
                </p:column>
            </p:dataTable>

            <p:spacer height="10px" />

            <p:panel id="details" header="Details">
                <h:panelGrid columns="5" rendered="#{roomsBackingBean.reservationSelected}">
                    <h:outputLabel for="resFrom" value="From:" />
                    <p:calendar id="resFrom" value="#{roomsBackingBean.selectedReservation.resFrom}"/>
                    <h:inputText id="resFromHour" value="#{roomsBackingBean.selectedReservation.resFromHour}" size="2" />
                    <h:inputText id="resFromMinute" value="#{roomsBackingBean.selectedReservation.resFromMinute}" size="2"/>
                    <h:panelGrid columns="1">
                        <p:message for="resFrom" />
                        <p:message for="resFromHour" />
                        <p:message for="resFromMinute" />
                    </h:panelGrid>

                    <h:outputLabel for="resTo" value="Until:" />
                    <p:calendar id="resTo" value="#{roomsBackingBean.selectedReservation.resTo}"/>
                    <h:inputText id="resToHour" value="#{roomsBackingBean.selectedReservation.resToHour}" size="2"/>
                    <h:inputText id="resToMinute" value="#{roomsBackingBean.selectedReservation.resToMinute}" size="2"/>
                    <h:panelGrid columns="1">
                        <p:message for="resTo" />
                        <p:message for="resToHour" />
                        <p:message for="resToMinute" />
                    </h:panelGrid>

                    <h:outputLabel for="people" value="# people:" />
                    <h:inputText id="people" value="#{roomsBackingBean.selectedReservation.numberOfPeople}"
                                 label="Number of people"/>
                    <h:outputText value="&nbsp;"/>
                    <h:outputText value="&nbsp;"/>
                    <p:message for="people" />

                    <h:outputLabel for="contact" value="Contact person:" />
                    <h:inputText id="contact" value="#{roomsBackingBean.selectedReservation.contactPerson}"
                                 label="Contact person:"/>
                    <h:outputText value="&nbsp;"/>
                    <h:outputText value="&nbsp;"/>
                    <p:message for="contact" />

                    <h:outputText value="&nbsp;"/>
                    <p:commandButton action="#{roomsBackingBean.updateReservation}"
                                     ajax="false"
                                     update="table"
                                     value="Save" />
                </h:panelGrid>
            </p:panel>
        </h:form>
    </h:body>
</html>
